﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Maticsoft.DBUtility;

namespace MedManager
{
    public partial class DrugInfo : Form
    {
        public DrugInfo()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindData()
        {
            StringBuilder sql = new StringBuilder("select id as '编号'");
            sql.Append(",name as '药品名称'");
            sql.Append(",inventory as '库存'");
            sql.Append(",price as '价格'");
            sql.Append(" from medInfo");
            sql.Append(" where name like '%" + txtDrugName.Text + "%'");
            DataTable dt = DbHelperSQL.Query(sql.ToString()).Tables[0];
            dgvDrugList.DataSource = dt;
        }

        private void InitControl()
        {
            if (Src.Func.user.type == 1)
            {
                btnAdd.Visible = false;
            }
        }

        private void DrugInfo_Load(object sender, EventArgs e)
        {
            InitControl();
            BindData();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            Drug drugFrm = new Drug();
            drugFrm.MdiParent = this.MdiParent;
            drugFrm.Text = "增加药品";
            drugFrm.DrugName = txtDrugName.Text.Trim();
            drugFrm.Show();
        }
    }
}
